<?php
/**
 * Created by PhpStorm.
 * User: wufubin
 * Date: 2017/1/3
 * Time: 20:27
 */

namespace Home\Controller;


use Common\Controller\HomeController;
use Common\Model\GoodsModel;
use Org\Util\Cart;

class CartController extends HomeController {
    public function index() {
        $headConf = [
            'title' => '购物车',
            'js' => ['list']
        ];
        $this->assign('headConf', $headConf);
        $data = $_SESSION['cart'] ? $_SESSION['cart'] : [];
        foreach ($data['goods'] as $k => $v) {
            $data['goods'][$k]['pic'] = (new GoodsModel())->where("gid = {$v['id']}")->getField('pic');
        }

        p($data);
        $this->assign('data', $data);
        $this->display();
    }

    public function ajaxUpdateCart() {
        $num = $_POST['num'];
        $sid = $_POST['sid'];
        $data = [
            'sid' => $sid,
            'num' => $num,
        ];
        (new Cart())->update($data);
    }
}